home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
CGI shell
/
length.4th
< prev
next >
Wrap
Text File
|
1995-10-30
|
2KB
|
101 lines
\
\ Physics Units Conversions - Length
\
\ Ronald T. Kneusel, rkneusel@post.its.mcw.edu, 27-Oct-95
\
\ Last mod: 30-Oct-95
\
\
\ All conversions are a table lookup. The calculation is:
\
\ dest value = (array[dest]/array[source]) * source value
\
\ where array[dest] returns the address of a floating point
\ constant for that conversion
\
( load CGIshell, template code )
--> CGIshell.4th
--> template.4th
( strings and such )
$[ fname length.txt] \ template filename
message[ src source] \ field names
message[ dst dest]
message[ val value]
2048 String>> out \ output string
30 String>> ans \ answer goes here
30 String>> org \ initial value
30 String>> s \ scratch
2 array>> A ans 0 A !array \ setup answer
org 1 A !array
( use template's array words for the conversion array )
15 array>> ang
( length constants )
: >ang ( v indx -- ) ang !array ;
fvariable &0 fvariable &1 fvariable &2 fvariable &3
fvariable &4 fvariable &5 fvariable &6
fvariable &7 fvariable &8 fvariable &9 fvariable &10
fvariable &11 fvariable &12 fvariable &13
&0 0 >ang &1 1 >ang &2 2 >ang &3 3 >ang &4 4 >ang &5 5 >ang
&6 6 >ang &7 7 >ang &8 8 >ang &9 9 >ang &10 10 >ang
&11 11 >ang &12 12 >ang &13 13 >ang
( other variables )
fvariable x fvariable y \ value and answer
variable i variable j
( setup array values )
1.0 &0 f! 1.0e10 &1 f! 6.685e-12 &2 f! 100.0 &3 f!
1.0e15 &4 f! 3.281 &5 f! 39.37 &6 f! 1.0e-3 &7 f!
1.057e-16 &8 f! 1.0e6 &9 f! 5.400e-4 &10 f! 6.214e-4 &12 f!
3.241e-17 &11 f! 1.094 &13 f!
( do the conversion )
: calc ( -- ) \ calculate
j @ ang @array f@ i @ ang @array f@ f/ \ array[dest]/array[source]
x f@ f* y f!
;
: f< ( f1 f2 -- f1<f2 ) fcompare >r fdrop fdrop r> -1 = ;
: f> ( f1 f2 -- f1>f2 ) fcompare >r fdrop fdrop r> 1 = ;
: pp ( -- ) \ set the output number format
y f@ fabs fdup
0.009 f> >r 100000.0 f< r> and
IF 6 fix ELSE 6 sci THEN ;
( Apple Event handler )
,s sdoc ,s WWWΩ ae:
s src NEW @Field s str>f f>d drop i ! \ conversion type
s dst NEW @Field s str>f f>d drop j !
org val NEW @Field org str>f x f! \ value to convert
calc \ calculate answer
pp y f@ ans f>str \ answer into string
out A fname NEW template \ build reply
out REPLY \ send reply
bye
;ae